package com.rongshu.view.home.presenter;

import android.content.Context;

import com.rongshu.api.RetorfitService;
import com.rongshu.view.base.mvp.BasePresenter;
import com.rongshu.view.home.contract.PeopleRecommendView;
import com.rongshu.view.home.entity.PeopleRecommendRespose;

import java.util.List;

import rx.Subscriber;
import rx.functions.Func1;

public class PeopleRecommendPresenter extends BasePresenter<PeopleRecommendView> {

    public PeopleRecommendPresenter(Context context) {
        super(context);
    }

    /**
     * 获取个人推荐语列表
     */
    public void getOneRecommendMsg(int contribute_id, int contribute_type,
                                   int from_uid, int pageIndex, int pageSize, String sign) {
        RetorfitService.getOneRecommendMsg(contribute_id, contribute_type,
                from_uid, pageIndex, pageSize, sign)
                .map(new Func1<PeopleRecommendRespose, List<PeopleRecommendRespose.ResponseBean>>() {
                    @Override
                    public List<PeopleRecommendRespose.ResponseBean> call(PeopleRecommendRespose peopleRecommendRespose) {
                        return peopleRecommendRespose.getResponse();
                    }
                })
                .subscribe(new Subscriber<List<PeopleRecommendRespose.ResponseBean>>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(List<PeopleRecommendRespose.ResponseBean> responseBeans) {
                        if (getView() != null) {
                            getView().onPeopleRecommend(responseBeans);
                        }
                    }
                });

    }
}
